Skip to content

feat(cli): support session forking and history loading in CLI#20

Merged
AstraBert merged 5 commits into
AstraBert:mainfrom
srimon12:feat/cli-session-fork
Jul 5, 2026
Merged

feat(cli): support session forking and history loading in CLI#20
AstraBert merged 5 commits into
AstraBert:mainfrom
srimon12:feat/cli-session-fork

Conversation

@srimon12

@srimon12 srimon12 commented Jun 29, 2026

Copy link
Copy Markdown
Contributor

Adds a --fork <session_id> CLI flag to allow initializing a new session from an existing parent session's history.

This copies events from the specified parent session to the new child session on startup and records a SessionFork event.

Key Changes:

  • Added a --fork option to CLI arguments.
  • Pre-populates the new session's event history with the parent session's events from the backend store on initialization.

Summary by CodeRabbit

  • New Features

    • Added a --fork <ID> option to create a new session seeded with the selected session’s saved history.
    • Both the headless agent run and the TUI now use the newly created session ID.
    • Introduced a session.fork event as part of the updated event protocol.
  • Bug Fixes

    • Forking now errors when the parent session has no stored events, preventing empty-session forks.

@coderabbitai

coderabbitai Bot commented Jun 29, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

Warning

Review limit reached

@AstraBert, you've reached your PR review limit, so we couldn't start this review.

Next review available in: 49 minutes

Enable usage-based reviews in Billing to review now. Otherwise, wait until the next included review is available.
You're only billed for reviews past your plan's rate limits ($0.25/file).

How can I continue?

After more reviews become available, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

To avoid repeated limits, reduce automatic review volume by pausing incremental auto-reviews earlier, using label-based review opt-in, excluding WIP or generated PR titles, or requesting reviews manually when the PR is ready. If your team needs uninterrupted high-volume reviews, an organization admin can enable usage-based reviews.

How do review limits work?

CodeRabbit enforces per-developer PR review limits for each organization. Most developers receive the normal plan review availability.

For paid Pro and Pro+ PR reviews, CodeRabbit uses adaptive limits for sustained high-volume activity. When a developer's recent PR review activity reaches the 95th percentile or higher among CodeRabbit users, additional reviews become available more gradually as earlier reviews age out of the rolling window.

Please refer docs for additional details.

Review details
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro Plus

Run ID: 14038c7b-aef5-41ca-a123-9ea6cc6b109b

📥 Commits

Reviewing files that changed from the base of the PR and between efa2a92 and d555fc4.

📒 Files selected for processing (1)
  • microagents-cli/src/main.rs
📝 Walkthrough

Walkthrough

Adds a session-forking CLI path, introduces a new session.fork event, updates JSON-RPC event handling, and bumps crate and dependency versions across the workspace.

Changes

Session Fork Flow

Layer / File(s) Summary
Event protocol and serialization
microagents-events/src/lib.rs
SessionForkEvent is added, event JSON-RPC serialization is centralized, AgentEventAny becomes serde-tagged for method/params, and JSON-RPC notifications are deserialized through the new enum shape.
CLI fork resolution
microagents-cli/src/main.rs
--fork is added, the parent session is cloned into a new UUID session, and the resolved session ID is used by both the headless run and TUI startup paths.
Workspace version bumps
microagents-cli/Cargo.toml, microagents-core/Cargo.toml, microagents-events/Cargo.toml, microagents-storage/Cargo.toml, search-evals/Cargo.toml
Crate versions and local dependency version pins are updated across the workspace, and chrono is added to microagents-cli.

Estimated code review effort: 4 (Complex) | ~45 minutes

Possibly related PRs

  • AstraBert/microagents#5: Both changes alter microagents-events/src/lib.rs JSON-RPC and AgentEventAny handling, and this PR adds session.fork on top of that refactor.
  • AstraBert/microagents#14: Both changes thread a resolved session identifier through agent execution paths.

Poem

A rabbit found a fork in time,
and cloned a trail in tidy rhyme.
New UUID, old echoes sing,
then hop! the TUI joins the spring.

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly summarizes the main CLI change: session forking with history loading.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 2

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@microagents-cli/src/main.rs`:
- Around line 140-156: The fork flow in main currently clones parent events and
returns the new session id, but it never persists the SessionFork marker event.
After the child session is created in the event replay loop, add a write for the
SessionFork event through storage so the lineage is recorded distinctly from a
normal resumed session. Use the existing session-writing path in main alongside
the SessionInit and other event handling to place this marker at the right point
in the fork process.
- Around line 163-169: The forked startup logic in main.rs is treating
`--session-id` as the only way to continue into the TUI after `fork_session`,
which makes plain `--fork <parent>` exit early unless an unrelated value is
passed. Update the `resolved_session_id` handling so the forked TUI path uses
`Some(new_sid)` when `args.fork` is present and no prompt is provided, and
reserve the early return only for an explicit clone-only mode if you add one.
Keep the fix centered on `fork_session`, `resolved_session_id`, and the
`args.prompt` / `args.session_id` branch.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro Plus

Run ID: 8d1dc15b-0b86-4d31-acde-a6eaaebc6a2f

📥 Commits

Reviewing files that changed from the base of the PR and between a5408c9 and 34c9ab8.

📒 Files selected for processing (1)
  • microagents-cli/src/main.rs

Comment thread microagents-cli/src/main.rs
Comment thread microagents-cli/src/main.rs

@AstraBert AstraBert left a comment

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This looks good, thanks for simplifying the codebase and the to/from json-rpc conversion! gonna merge only this one since the other one contains basically the same logic for events to/from json-rpc conversion

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 2

🧹 Nitpick comments (1)
microagents-events/src/lib.rs (1)

293-293: 🗄️ Data Integrity & Integration | 🔵 Trivial | ⚡ Quick win

Cover the non-null tool_calls serialization path.

Line 293 now routes AssistantResponseEvent through generic serde serialization, but the existing serialization test only covers tool_calls: None. Add a Some(vec![...]) serialization or round-trip assertion so the wire shape stays locked down after replacing the prior special handling.

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@microagents-events/src/lib.rs` at line 293, The AssistantResponseEvent
serialization change only has coverage for the tool_calls: None case, so add a
test that exercises the non-null tool_calls path and verifies the JSON-RPC wire
shape. Update the serialization/round-trip test around AssistantResponseEvent
and serialize_to_jsonrpc to include tool_calls as Some(vec![...]) so the generic
serde path stays locked down.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@microagents-cli/src/main.rs`:
- Around line 139-152: The history cloning in main.rs is copying inherited
SessionFork markers from the parent and then adding a new fork marker for the
child, which leaves the new session with two fork origins. Update the
parent_events replay loop so SessionFork events are skipped (or otherwise not
rewritten/persisted) while cloning history, and only append the new
child-to-parent fork marker once after the loop. Use the existing event handling
around cloned_event, SessionInit, and storage.update_session/create_session to
locate the change.
- Around line 49-51: The CLI options are ambiguous because `fork` currently
overrides `session_id` silently; update the argument definitions in `main.rs` so
`--fork` and `--session-id` cannot be used together. Add the conflict on the
`fork` field in the argument struct, using the existing `fork` and `session_id`
symbols, so the parser rejects the combination instead of choosing one
implicitly.

---

Nitpick comments:
In `@microagents-events/src/lib.rs`:
- Line 293: The AssistantResponseEvent serialization change only has coverage
for the tool_calls: None case, so add a test that exercises the non-null
tool_calls path and verifies the JSON-RPC wire shape. Update the
serialization/round-trip test around AssistantResponseEvent and
serialize_to_jsonrpc to include tool_calls as Some(vec![...]) so the generic
serde path stays locked down.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro Plus

Run ID: 72b1fbce-7f34-455d-8946-dd9fbfea3745

📥 Commits

Reviewing files that changed from the base of the PR and between 34c9ab8 and efa2a92.

⛔ Files ignored due to path filters (1)
  • Cargo.lock is excluded by !**/*.lock
📒 Files selected for processing (7)
  • microagents-cli/Cargo.toml
  • microagents-cli/src/main.rs
  • microagents-core/Cargo.toml
  • microagents-events/Cargo.toml
  • microagents-events/src/lib.rs
  • microagents-storage/Cargo.toml
  • search-evals/Cargo.toml
✅ Files skipped from review due to trivial changes (1)
  • search-evals/Cargo.toml

Comment thread microagents-cli/src/main.rs
Comment thread microagents-cli/src/main.rs
@AstraBert AstraBert merged commit 593a4fd into AstraBert:main Jul 5, 2026
6 checks passed
@srimon12 srimon12 deleted the feat/cli-session-fork branch July 5, 2026 20:08
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants